package Meituan;

import java.util.Random;

/**
 * 伯努利定理
 * @author: leiwenkang02@meituan.com
 * @date: 2019/3/4
 * @time: 15:52
 */
public class BonuliTest {

    public static void main(String[] args) {
        int count = 10000000;
        int count1 = 0;
        int count2 = 0;
        int count3 = 0;
        int count4 = 0;
        for (int i = 0; i < count; i++) {
            int num =  getNum();
            if (num == 1) {
                count1++;
            } else if (num == 2) {
                count2++;
            } else if (num == 3) {
                count3++;
            } else if (num == 4) {
                count4++;
            }
        }
        System.out.println("1出现的次数为： " + count1);
        System.out.println("2出现的次数为： " + count2);
        System.out.println("3出现的次数为： " + count3);
        System.out.println("4出现的次数为： " + count4);

    }

    /**
     * 10% 1
     * 20% 2
     * 30% 3
     * 40% 4
     */
    public static int getNum() {
        int randomNum = new Random().nextInt(100);
        if (randomNum < 10) {
            return 1;
        } else if (randomNum < 30) {
            return 2;
        } else if (randomNum < 60) {
            return 3;
        } else {
            return 4;
        }
    }
}
